#ifndef SUMORTISTATICLIB_SUMORTI_H
#define SUMORTISTATICLIB_SUMORTI_H

#include <ostream>
#include "entity.h"
#include <RTI.hh>
#include <fedtime.hh>
#include "HwFederateAmbassador.hh"

#include <libsumo/libsumo.h>

using namespace libsumo;

int logConfig(int argc, char *argv[]);

SumoArguments parameterAnalysis(int argc, char *argv[]);

/**
 * RTI助手类
 */
class RTIHelper {
private:
    char *federationExecutionName = nullptr;
    char *fedFile = nullptr;
    char *federateName = nullptr;

    RTI::RTIambassador rti;
    HwFederateAmbassador fedAmb;
    RTI::FederateHandle federateId;
    RTIfedTime lookahead = 0; // RTI联邦超前时
public:
    RTIHelper(char *federationExecutionName, char *fedFile, char *federateName);

    virtual ~RTIHelper();

    friend ostream &operator<<(ostream &os, const RTIHelper &helper);

    /**
     * 创建联邦执行
     * @return 返回RTI::RTIambassador
     */
    RTIambassadorReturn createFederationExecution();

    /**
     * 加入联邦执行
     * @return 返回FederateHandleReturn
     */
    FederateHandleReturn joinFederationExecution();

    /**
     * 注销联邦执行
     * @return
     */
    int resignFederationExecution();

    /**
     * 摧毁联邦执行
     * @return
     */
    int destroyFederationExecution();


};

/**
 * SumoRti的助手类
 */
class SumoRtiHelper {
public:
    SumoRtiHelper(SumoArguments sumoArguments);

    void sendSumoVehInteraction(RTI::RTIambassador rti,
                                       const SubscriptionResults &allSubscriptionResults,
                                       map<string, RTI::ParameterHandle> hSumoList,
                                       RTI::InteractionClassHandle hSumoClass);

    map<string, RTI::ParameterHandle>
    getParameterHandle(const RTIambassadorReturn &rtiReturn, RTI::InteractionClassHandle hSumoClass);

    RTI::ObjectHandle processingNetworkOffset(RTI::RTIambassador rti, SumoArguments sumoArguments);
};

#endif //SUMORTISTATICLIB_SUMORTI_H
